package com.whksoft.mymapplugin.Listener;

import com.whksoft.mymapplugin.API.Event.PaymentCanceledEvent;
import com.whksoft.mymapplugin.utils.CancelReason;
import com.whksoft.mymapplugin.utils.itemUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;

/**
 * 检测玩家离开游戏
 */
public class playerLeave implements Listener {
    Plugin plugin;

    public playerLeave(Plugin plugin) {
        this.plugin = plugin;
    }

    //扫码地图会在玩家离开的时候自动消失
    @EventHandler(priority = EventPriority.HIGHEST)
    public void playerQuit(PlayerQuitEvent e) {
        PaymentCanceledEvent event = new PaymentCanceledEvent(e.getPlayer(), CancelReason.PLAYER_LEAVE);
        Bukkit.getPluginManager().callEvent(event);
        if(!event.isCancelled()){
            itemUtils.clearMaps(e.getPlayer());
        }
    }
}
